using System;
using ErrorDumper.Configuration;
using ErrorDumper.Providing;

namespace ErrorDumper
{
    public static class ExceptionProvider
    {
        static IExceptionProvider _current;
        static readonly object _sync = new object();

        public static IExceptionProvider Current {
            get {
                IExceptionProvider current;
                lock (_sync)
                    if ((current = _current) != null)
                        return current;

                current = FromConfig();

                lock (_sync)
                    return _current = current;
            }
            set {
                lock (_sync)
                    _current = value;
            }
        }

        public static IExceptionProvider FromConfig() {
            //var config = ErrorDumperSectionGroup.GetValidatedSection();
            //var providerConfig = config.Provider;
            //switch (providerConfig.Ref.ToLower()) {
            //    case "":
            //        var typeName = providerConfig.ProviderType;
            //        if (string.IsNullOrEmpty(typeName))
            //            return null;
            //        var providerType = Type.GetType(typeName, true);
            //        return (IExceptionProvider)Activator.CreateInstance(providerType, ExceptionHandler.GetConnectionString());
            //    case "sql":
            //        return new SqlExceptionProvider(ExceptionHandler.GetConnectionString());
            //    default:
            //        throw new ArgumentOutOfRangeException("config");
            //}
            throw new NotImplementedException();
        }
    }
}